package cn.jbolt.ai.app;

import cn.hutool.core.util.StrUtil;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public enum AppType {
    SIMPLE("app_simple", "简单应用"),
    DESIGN("app_design", "编排应用");


    private String code;
    private String description;


    // 私有构造函数
    private AppType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据code查找对应的description
     * @param code
     * @return
     */
    public static AppType getByCode(String code) {
        if (StrUtil.isEmpty(code)) {
            throw new IllegalArgumentException("AppType code 不能为 null");
        }
        return Arrays.stream(values())
                .filter(type -> type.getCode().equals(code))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("未找到匹配的 AppType : " + code));
    }

    public static List<Map<String, Object>> toList() {
        return java.util.Arrays.stream(AppType.values())
                .map(type -> {
                    Map<String, Object> map = new java.util.HashMap<>();
                    map.put("value", type.getCode());
                    map.put("text", type.getDescription());
                    return map;
                })
                .collect(Collectors.toList());
    }
}
